﻿Imports EHaskins.Frc.Dashboard
Imports System.IO
Public Class OutputDataProcessor
    Inherits DefaultUserDataProcessor
    Implements IOutputDataProcessor

    Dim _pwms(9) As Pwm

    Public Sub New()
        SetId(1103, 4)

        For i = 0 To 9
            _pwms(i) = New Pwm(i + 1, 128)
        Next
    End Sub

    Public Overrides Function Parse(ByVal data() As Byte) As Byte()
        Dim d = MyBase.Parse(data)
        Return ShallowParse(d)
    End Function

    Public Overrides Function ShallowParse(ByVal data() As Byte) As Byte()
        If data IsNot Nothing Then
            Dim reader As New BinaryReader(New MemoryStream(data))

            For i = 0 To 9
                'normalize to -1 to 1.
                Dim b As Byte = reader.ReadByte()
                Pwms(i).RawValue = b
            Next
        End If
        Return Nothing
    End Function
    Public Property Pwms() As Pwm() Implements IOutputDataProcessor.Pwms
        Get
            Return _pwms
        End Get
        Set(ByVal value As Pwm())
            _pwms = value
            RaisePropertyChanged("Pwms")
        End Set
    End Property


End Class
